/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import static persistencia.DBManagerPacientes.conexion;
import modelo.Pacientes;
import modelo.MetodosPacientes;


/**
 *Panel donde se pintaran las consultas en un JTable
 * @author Kevin
 */
public class JPConsultas extends javax.swing.JPanel {
    
    ResultSet rs;
    ArrayList<Pacientes> al;
    String[] columns = new String [] {
                "Nombre", "1ºApellido", "2ºApellido", "DNI", "Dirección","Población","Cod Postal","Cod Paciente"
            };
    
    String path = "../img/iconosclasificacionenergetica/";
    class MyTableModel extends DefaultTableModel{
        
        @Override
        public Class getColumnClass(int column)
        {
            switch(column) {
                case 0:
                case 1: return String.class;
                case 2: return Integer.class;
                case 3: return String.class;
                case 4: return ImageIcon.class;
                default: return Object.class;
            }
        }
    }  
    
    public void actualizarComboPaciente() throws SQLException, ClassNotFoundException{
        jComboCodPaciente.removeAllItems();
        MetodosPacientes mtp = new MetodosPacientes ();
        al = mtp.getIPacientes();
        for (int i = 0; i < al.size(); i++) {
            jComboCodPaciente.addItem(al.get(i).getNombre()); //+al.get(i).getNombre());
        }
    }

    
    
    private void rellenarJTable(ResultSet rs) {
         try {
            MyTableModel dtm = new MyTableModel();
            dtm.setColumnIdentifiers(columns);
            
            Object [] obj;
            while (rs.next()) {
                obj = new Object[8];
                obj[0]= rs.getString("Nombre");
                obj[1]= rs.getString("1ºApellido");
                obj[2] = rs.getString("2ºApellido");
                obj[3] = rs.getString("DNI");
                obj[4] = rs.getString("Dirección");
                obj[5] = rs.getString("Población");
                obj[6] = rs.getInt("Cod Postal");
                obj[7] = rs.getInt("Cod Paciente");
                
                
                            
                System.out.println("1111");
            }

            jTablePacientes.setModel(dtm);
        } catch (Exception e) {
            e.printStackTrace();
        }       
    }
    /**
     * Creates new form JPConsultas
     */
    public JPConsultas() throws SQLException, ClassNotFoundException /*throws SQLException, ClassNotFoundException*/ {
        initComponents();
        jButtonConsultar.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                
                }

        });
        
            

           

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jButtonConsultar = new javax.swing.JButton();
        CodPaciente = new java.awt.Label();
        DniPaciente = new java.awt.Label();
        jtextDNIPACIENTE = new java.awt.TextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTablePacientes = new javax.swing.JTable();
        jComboCodPaciente = new javax.swing.JComboBox();
        jTextTitulo = new javax.swing.JLabel();

        setLayout(new java.awt.GridBagLayout());

        jButtonConsultar.setText("Consultar");
        jButtonConsultar.setToolTipText("");
        jButtonConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonConsultarActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.ipady = 20;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(10, 125, 0, 0);
        add(jButtonConsultar, gridBagConstraints);

        CodPaciente.setText("Código Paciente:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(37, 28, 0, 0);
        add(CodPaciente, gridBagConstraints);
        CodPaciente.getAccessibleContext().setAccessibleName("Producto: ");

        DniPaciente.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        DniPaciente.setName(""); // NOI18N
        DniPaciente.setText("DNI del Paciente:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(10, 27, 0, 0);
        add(DniPaciente, gridBagConstraints);
        DniPaciente.getAccessibleContext().setAccessibleName("");

        jtextDNIPACIENTE.setMinimumSize(new java.awt.Dimension(300, 20));
        jtextDNIPACIENTE.setName("emisionesText"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(10, 24, 0, 0);
        add(jtextDNIPACIENTE, gridBagConstraints);

        jTablePacientes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Nombre", "1º Apellido", "2º Apellido", "DNI", "Dirección", "Población", "Cod Postal", "Cod Paciente"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTablePacientes);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 554;
        gridBagConstraints.ipady = 63;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(11, 10, 11, 10);
        add(jScrollPane1, gridBagConstraints);

        jComboCodPaciente.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.ipadx = 244;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(37, 24, 0, 0);
        add(jComboCodPaciente, gridBagConstraints);

        jTextTitulo.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jTextTitulo.setText("Consultas sobre Paciente");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(19, 24, 0, 0);
        add(jTextTitulo, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConsultarActionPerformed

    }//GEN-LAST:event_jButtonConsultarActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.awt.Label CodPaciente;
    private java.awt.Label DniPaciente;
    private javax.swing.JButton jButtonConsultar;
    private javax.swing.JComboBox jComboCodPaciente;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTablePacientes;
    private javax.swing.JLabel jTextTitulo;
    private java.awt.TextField jtextDNIPACIENTE;
    // End of variables declaration//GEN-END:variables
}
